package com.qf.lanzhou.blog.api.service.impl.login;

import com.qf.lanzhou.blog.api.dao.AuditDao;
import com.qf.lanzhou.blog.api.dao.Impl.login.AuditDaoImpl;
import com.qf.lanzhou.blog.api.dao.Impl.login.UserDaoImpl;
import com.qf.lanzhou.blog.api.dao.UserDao;
import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.service.ForgetPasswordService;



/**
 * @author LEON-HE
 */
public class ForgetPasswordServiceImpl implements ForgetPasswordService {
    private UserDao userDao = new UserDaoImpl();
    private AuditDao auditDao = new AuditDaoImpl();

    @Override
    public String checkPhone(String phone) {
        String username = userDao.selectUserNameByPhone(phone);
        if (username!=null){
            return username;
        }
        throw new RuntimeException("查找不到该用户，请重新进行验证");
    }

    @Override
    public void updateAudit(String username) {
        User user = userDao.selectUserByUserName(username);
        if (!auditDao.selectAuditByUserId(user.getId())){
            throw new RuntimeException("正在审核请耐心等候！！！");
        }
        if (auditDao.saveAuditChangePassword(user.getId())){
            return;
        }
        throw new RuntimeException("系统繁忙，请重试");
    }
}
